home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------------------
- //
- // MyApplication Shell.
- // by John Wang
- //
- // Description: Shell.
- //
- // Version: 1.0 09/07/93 Completed.
- //
- //--------------------------------------------------------------------------
-
- // #includes:
-
- #include <EPPC.h> // Need constants to resume/suspend.
- #include <GestaltEqu.h> // Check for System 7.
- #include <AppleEvents.h> // Core AppleEvents is implemented.
-
- #include "MyApplication Shell (1.0).h"
- #include "MyApplication.h"
-
- //--------------------------------------------------------------------------
-
- // Globals:
-
- Boolean gDoneFlag; // Set to TRUE if you want to Application to kindly quit.
- Boolean gHasAppleEvents; // TRUE if Gestalt returns saying AppleEvents is available.
- short gScrapCount; // Keep track of scrap count.
- OSType gScrapType; // Needed to know what type scrap it is.
- Handle gScrap; // Must keep a handle to the scrap for update events that
- // happen in the background. The reason is that when the app
- // is in the background, it does not have access to GetScrap().
-
- //--------------------------------------------------------------------------
-
- // main:
-
- void main()
- {
- EventRecord myEvent;
- long yieldTime;
- WindowPtr foundWindow;
- short windowPart;
- Boolean isEvent;
- GrafPtr savePort;
- GDHandle saveGD;
- PScrapStuff myScrapStuff;
-
- // Initialize here. Set the yield time too.
- MAS_initialize();
- yieldTime = MyYieldTime(suspendResumeMessage);
-
- // Event loop.
- for (;;) {
-
- // Get the event.
- isEvent = WaitNextEvent(everyEvent, &myEvent, yieldTime, nil);
-
- // Allow application specific event handling. We have three cases:
- // MYEVENTDEF == 2: MyEvent gets called for each window.
- // MYEVENTDEF == 1: MyEvent gets once with window parameter = nil.
- // MYEVENTDEF == 0: MyEvent never gets called.
- // MyEvent returns TRUE to indicate that the event is handled and can be ignored.
- // As the safe thing to do, we always set the port if we know what window is being used.
- #if MYEVENTDEF == 2
- if (isEvent) {
- foundWindow = (WindowPtr) WindowList;
- while (foundWindow != nil) {
- if (IsMyWindow(foundWindow)) {
- GetPort(&savePort);
- saveGD = GetGDevice();
- SetPort(foundWindow);
- SetGDevice(GetMainDevice());
- if (MyEvent(foundWindow, &myEvent))
- isEvent = FALSE;
- SetPort(savePort);
- SetGDevice(saveGD);
- }
- foundWindow = (WindowPtr) ((CWindowPeek) foundWindow)->nextWindow;
- }
- }
- #elif MYEVENTDEF == 1
- if (isEvent) {
- if (MyEvent(nil, &myEvent)) {
- isEvent = FALSE;
- }
- }
- #elif MYEVENTDEF == 0
- #endif
-
- // If the event is unhandled by app specific event handling, then we proceed.
- if (isEvent) {
- switch (myEvent.what) {
-
- case mouseDown:
- // Get current port and device.
- GetPort(&savePort);
- saveGD = GetGDevice();
-
-
- // Set the port and gdevice to the window if we own the window.
- // We can then assume anytime the event occured in one of our windows,
- // that the port and gdevice are set correctly.
- windowPart = FindWindow(myEvent.where, &foundWindow);
- if (IsMyWindow(foundWindow) || IsMyClipWindow(foundWindow)) {
- SetPort(foundWindow);
- SetGDevice(GetMainDevice());
- }
-
- // Handle the different mouse down events.
- switch (windowPart) {
- case inSysWindow:
- SystemClick(&myEvent, foundWindow);
- break;
- case inMenuBar:
- MAS_adjustMenus();
- MAS_doCommand(MenuSelect(myEvent.where));
- break;
- case inContent:
- // If in the content area of application's window, then select
- // the window and call app specific routine.
- if (IsMyWindow(foundWindow)) {
- SelectWindow(foundWindow);
- MyInContent(foundWindow, myEvent.where);
- } else if (IsMyClipWindow(foundWindow)) {
- SelectWindow(foundWindow);
- }
- break;
- case inDrag:
- // If dragging one of the application's windows, then handle it.
- // However, if we are dragging a zoomed window, we
- // must remember to save the new window location into the
- // zoomed rect in the data handle. Otherwise, the event
- // manager will think that we are no longer zoomed.
- if (IsMyWindow(foundWindow) || IsMyClipWindow(foundWindow)) {
- WStateData *zoomData;
- Rect windowRect;
-
- // Get window location before drag.
- MAS_GetGlobalWindow(foundWindow, &windowRect);
-
- // Drag window.
- DragWindow (foundWindow, myEvent.where, &qd.screenBits.bounds);
-
- // If the windowRect in global coordinates matches the zoom rect,
- // then assume that we are dragging the zoomed window. update
- // zoom rect.
- zoomData = (WStateData *) *(((CWindowPeek) foundWindow)->dataHandle);
- if (EqualRect(&(zoomData->stdState), &windowRect)) {
- MAS_GetGlobalWindow(foundWindow, &windowRect);
- zoomData = (WStateData *) *(((CWindowPeek) foundWindow)->dataHandle);
- zoomData->stdState = windowRect;
- }
- }
- break;
- case inGrow:
- // If growing one of the application's windows, then handle it.
- // This also includes the clip window.
- // See inDrag for details.
- if (IsMyWindow(foundWindow) || IsMyClipWindow(foundWindow)) {
- WStateData *zoomData;
- Rect windowRect;
- Rect tempRect;
- long tempLong;
- Str255 tempStr;
-
- // Get window location before drag.
- MAS_GetGlobalWindow(foundWindow, &windowRect);
-
- // Grow the window.
- tempRect = qd.screenBits.bounds;
- tempRect.left = tempRect.top = 50;
- GetWTitle(foundWindow, tempStr);
- tempRect.left = StringWidth(tempStr) + 50;
- if (tempLong = GrowWindow(foundWindow, myEvent.where, &tempRect)) {
- tempRect = foundWindow->portRect;
- InvalRect(&tempRect);
- EraseRect(&tempRect);
- InvalRect(&tempRect);
- SizeWindow(foundWindow, tempLong, tempLong >> 16, true);
- }
-
- // If the windowRect in global coordinates matches the zoom rect,
- // then assume that we are dragging the zoomed window. update
- // zoom rect.
- zoomData = (WStateData *) *(((CWindowPeek) foundWindow)->dataHandle);
- if (EqualRect(&(zoomData->stdState), &windowRect)) {
- MAS_GetGlobalWindow(foundWindow, &windowRect);
- zoomData = (WStateData *) *(((CWindowPeek) foundWindow)->dataHandle);
- zoomData->stdState = windowRect;
- }
- }
- break;
- case inGoAway:
- // Handle clicking on the go away. If it is the clip window,
- // then hide it.
- if (TrackGoAway (foundWindow, myEvent.where)) {
- if (IsMyWindow(foundWindow)) {
- BringToFront(foundWindow);
- MyClose();
- } else if (IsMyClipWindow(foundWindow)) {
- SetItem(GetMHandle(MENU_EDITID), MENU_EDITSHOWCLIP, "\PShow Clipboard");
- MAS_hideClip(foundWindow);
- }
- }
- break;
- case inZoomIn:
- case inZoomOut:
- // Zoom application window and the clip window.
- if (TrackBox(foundWindow, myEvent.where, windowPart)) {
- if (IsMyWindow(foundWindow))
- MyZoomWindow(foundWindow, windowPart == 8);
- else if (IsMyClipWindow(foundWindow))
- MAS_zoomClip(foundWindow, windowPart == 8);
- ZoomWindow(foundWindow, windowPart, TRUE);
- }
- break;
- break;
- default:
- break;
- }
-
- // Restore port and device.
- SetPort(savePort);
- SetGDevice(saveGD);
-
- break;
- case keyDown:
- case autoKey:
- if ( myEvent.modifiers & cmdKey ) {
- if ( myEvent.what == keyDown ) {
- MAS_adjustMenus();
- MAS_doCommand(MenuKey(myEvent.message & charCodeMask));
- }
- } else
- MyDoKeyDown(&myEvent);
- break;
- case updateEvt:
- // Handle update events for window and clip window.
- foundWindow = (WindowPtr) myEvent.message;
- GetPort(&savePort);
- saveGD = GetGDevice();
- SetPort(foundWindow);
- SetGDevice(GetMainDevice());
- BeginUpdate(foundWindow);
- if (IsMyWindow(foundWindow))
- MyDraw(foundWindow);
- else if (IsMyClipWindow(foundWindow))
- MAS_drawClip(foundWindow);
- EndUpdate(foundWindow);
- SetPort(savePort);
- SetGDevice(saveGD);
- break;
- case diskEvt:
- // This handles a bad disk. Otherwise the disk will not eject.
- if (myEvent.message >> 16) {
- Point tempPoint;
- tempPoint.v = 50; tempPoint.h = 50;
- DIBadMount(tempPoint, myEvent.message);
- }
- break;
- case activateEvt:
- break;
- case app4Evt:
- switch (myEvent.message >> 24) {
- case suspendResumeMessage:
- yieldTime = MyYieldTime(myEvent.message & 0x01);
- break;
- default:
- DebugStr("\PUnexpected suspend/resume message.");
- }
- break;
- case kHighLevelEvent:
- if (gHasAppleEvents)
- AEProcessAppleEvent(&myEvent);
- default:
- break;
- }
- }
-
- // If DoneFlag set, then quit.
- if (gDoneFlag)
- MAS_finishup();
-
- // Do Idle routine.
- // MYIDLEDEF == 2: MyEvent gets called for each window.
- // MYIDLEDEF == 1: MyEvent gets once with window parameter = nil.
- // MYIDLEDEF == 0: MyEvent never gets called.
- // As the safe thing to do, we always set the port if we know what window is being used.
- #if MYIDLEDEF == 2
- foundWindow = (WindowPtr) WindowList;
- while (foundWindow != nil) {
- if (IsMyWindow(foundWindow)) {
- GetPort(&savePort);
- saveGD = GetGDevice();
- SetPort(foundWindow);
- SetGDevice(GetMainDevice());
- MyIdle(foundWindow);
- SetPort(savePort);
- SetGDevice(saveGD);
- }
- foundWindow = (WindowPtr) ((CWindowPeek) foundWindow)->nextWindow;
- }
- #elif MYIDLEDEF == 1
- MyIdle(nil);
- #elif MYIDLEDEF == 0
- #endif
-
- // See if scrap changed. If so, redraw if the clip window is found.
- myScrapStuff = InfoScrap();
- if (gScrapCount != myScrapStuff->scrapCount) {
- foundWindow = (WindowPtr) WindowList;
- while (foundWindow != nil) {
- if (IsMyClipWindow(foundWindow)) {
- GetPort(&savePort);
- saveGD = GetGDevice();
- SetPort(foundWindow);
- SetGDevice(GetMainDevice());
- MAS_drawClip(foundWindow);
- SetPort(savePort);
- SetGDevice(saveGD);
- }
- foundWindow = (WindowPtr) ((CWindowPeek) foundWindow)->nextWindow;
- }
- }
- }
- }
-
- //--------------------------------------------------------------------------
-
- // MyApplication Shell support routines (MAS_initialize, MAS_doCommand, and MAS_finishup):
-
- void MAS_initialize()
- {
- OSErr err;
- long vers;
- Handle myMenu;
-
- // Initialize Managaer.
- MaxApplZone();
- MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
- MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
- MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
- MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
- InitGraf(&qd.thePort);
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitDialogs(nil);
- InitCursor();
-
- // Set up menus.
- myMenu = GetNewMBar(MENUBAR);
- SetMenuBar(myMenu);
- DisposHandle(myMenu);
- AddResMenu(GetMHandle(MENU_APPLEID), 'DRVR');
- DrawMenuBar();
-
- // Require at least System 7.0. We don't really need to be strict about this.
- // So, this can be removed if necessary. But, test thoroughly with System 6 if you do.
- Gestalt(gestaltSystemVersion, &vers);
- vers = (vers >> 8) & 0x0f;
- if (vers < 7) {
- MAS_ReportError("\PThis Application does not run under System 6!", -1);
- ExitToShell();
- }
-
- // Initialize AppleEvents if available.
- gHasAppleEvents = (Gestalt(gestaltAppleEventsAttr, &vers) == noErr);
- if (gHasAppleEvents) {
- err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, AEOpenHandler, 0, FALSE);
- if (err) {
- MAS_ReportError("\PError installing AppleEvent handlers.", err);
- ExitToShell();
- }
- err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, AEOpenDocHandler, 0, FALSE);
- if (err) {
- MAS_ReportError("\PError installing AppleEvent handlers.", err);
- ExitToShell();
- }
- err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, AEQuitHandler, 0, FALSE);
- if (err) {
- MAS_ReportError("\PError installing AppleEvent handlers.", err);
- ExitToShell();
- }
- err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, AEPrintHandler, 0, FALSE);
- if (err) {
- MAS_ReportError("\PError installing AppleEvent handlers.", err);
- ExitToShell();
- }
- }
-
- // Setup other globals.
- gDoneFlag = FALSE;
-
- // Call app specific Intialization.
- if (MAS_ReportError("\PError returned from MyInitialize:", MyInitialize()))
- ExitToShell();
- }
-
- void MAS_doCommand(long mResult)
- {
- short theMenu, theItem;
- Str255 myStr;
- GrafPtr savePort;
- GDHandle saveGD;
- WindowPtr foundWindow;
-
- theItem = LoWord(mResult);
- theMenu = HiWord(mResult);
-
- if (theItem != 0 || theMenu != 0) {
- switch (theMenu) {
- case MENU_APPLEID:
- if (theItem == 1) {
- ParamText(gMyAboutTitle, gMyAboutDesc, nil, nil);
- Alert(ALERT_ABOUT, nil);
- } else {
- GetItem(GetMHandle(MENU_APPLEID), theItem, myStr);
- GetPort(&savePort);
- saveGD = GetGDevice();
- (void) OpenDeskAcc(myStr);
- SetPort(savePort);
- SetGDevice(saveGD);
- }
- break;
-
- case MENU_FILEID:
- switch (theItem) {
- case MENU_FILENEW:
- MyNew();
- break;
- case MENU_FILEOPEN:
- MyOpen(nil);
- break;
- case MENU_FILECLOSE:
- if (IsMyClipWindow(FrontWindow())) {
- SetItem(GetMHandle(MENU_EDITID), MENU_EDITSHOWCLIP, "\PShow Clipboard");
- MAS_hideClip(FrontWindow());
- } else if (IsMyWindow(FrontWindow()))
- MyClose();
- else
- SysBeep(50);
- break;
- case MENU_FILESAVE:
- if (IsMyWindow(FrontWindow()))
- MySave();
- else
- SysBeep(50);
- break;
- case MENU_FILESAVEAS:
- if (IsMyWindow(FrontWindow()))
- MySaveAs();
- else
- SysBeep(50);
- break;
- case MENU_FILEPAGESETUP:
- if (IsMyWindow(FrontWindow()))
- MyPageSetup();
- else
- SysBeep(50);
- break;
- case MENU_FILEPRINT:
- if (IsMyWindow(FrontWindow()))
- MyPrint();
- else
- SysBeep(50);
- break;
- case MENU_FILEQUIT:
- gDoneFlag = TRUE;
- break;
- default:
- if (MAS_ReportError("\PError in handling file menu:", theItem))
- ExitToShell();
- }
- break;
-
- case MENU_EDITID:
- switch (theItem) {
- case MENU_EDITUNDO:
- MyUndo();
- break;
- case MENU_EDITCUT:
- MyCut();
- break;
- case MENU_EDITCOPY:
- MyCopy();
- break;
- case MENU_EDITPASTE:
- MyPaste();
- break;
- case MENU_EDITCLEAR:
- MyClear();
- break;
- case MENU_EDITSELECTALL:
- MySelectAll();
- break;
- case MENU_EDITSHOWCLIP:
- GetItem(GetMHandle(MENU_EDITID), MENU_EDITSHOWCLIP, myStr);
- if (myStr[1] == 'S') { // Obviously not very internationalizeable.
- MAS_showClip();
- SetItem(GetMHandle(MENU_EDITID), MENU_EDITSHOWCLIP, "\PHide Clipboard");
- } else {
- foundWindow = (WindowPtr) WindowList;
- while (foundWindow != nil) {
- if (IsMyClipWindow(foundWindow)) {
- SetItem(GetMHandle(MENU_EDITID), MENU_EDITSHOWCLIP, "\PShow Clipboard");
- MAS_hideClip(foundWindow);
- }
- foundWindow = (WindowPtr) ((CWindowPeek) foundWindow)->nextWindow;
- }
- }
- break;
- default:
- if (MAS_ReportError("\PError in handling edit menu:", theItem))
- ExitToShell();
- }
- break;
-
- default:
- // If not handled above, then allow app specific handling to occur.
- if (MAS_ReportError("\PError returned from MyDoCommand:", MyDoCommand(theMenu, theItem)))
- ExitToShell();
- }
- }
- HiliteMenu(0);
- return;
- }
-
- void MAS_adjustMenus()
- {
- MenuHandle mHandle;
-
- if (IsMyClipWindow(FrontWindow())) {
- mHandle = GetMHandle(MENU_FILEID);
- DisableItem(mHandle, MENU_FILESAVE);
- DisableItem(mHandle, MENU_FILESAVEAS);
- DisableItem(mHandle, MENU_FILEPAGESETUP);
- DisableItem(mHandle, MENU_FILEPRINT);
- mHandle = GetMHandle(MENU_EDITID);
- DisableItem(mHandle, MENU_EDITUNDO);
- DisableItem(mHandle, MENU_EDITCUT);
- DisableItem(mHandle, MENU_EDITCOPY);
- DisableItem(mHandle, MENU_EDITPASTE);
- DisableItem(mHandle, MENU_EDITCLEAR);
- DisableItem(mHandle, MENU_EDITSELECTALL);
- } else {
- mHandle = GetMHandle(MENU_FILEID);
- if (IsMyWindow(FrontWindow())) {
- EnableItem(mHandle, MENU_FILESAVE);
- EnableItem(mHandle, MENU_FILESAVEAS);
- EnableItem(mHandle, MENU_FILEPAGESETUP);
- EnableItem(mHandle, MENU_FILEPRINT);
- } else {
- DisableItem(mHandle, MENU_FILESAVE);
- DisableItem(mHandle, MENU_FILESAVEAS);
- DisableItem(mHandle, MENU_FILEPAGESETUP);
- DisableItem(mHandle, MENU_FILEPRINT);
- }
- mHandle = GetMHandle(MENU_EDITID);
- EnableItem(mHandle, MENU_EDITUNDO);
- EnableItem(mHandle, MENU_EDITCUT);
- EnableItem(mHandle, MENU_EDITCOPY);
- EnableItem(mHandle, MENU_EDITPASTE);
- EnableItem(mHandle, MENU_EDITCLEAR);
- EnableItem(mHandle, MENU_EDITSELECTALL);
- }
-
- MyAdjustMenus();
- }
-
- void MAS_finishup()
- {
- WindowPtr frontWindow, nxtWindow;
-
- frontWindow = FrontWindow();
- while (frontWindow != nil) {
- nxtWindow = (WindowPtr) ((WindowPeek)frontWindow)->nextWindow;
- if (IsMyClipWindow(frontWindow)) {
- MAS_hideClip(frontWindow);
- }
- frontWindow = nxtWindow;
- }
-
- // Cleanup app specific stuff since all of the shell handles will be disposed of
- // when the heap disappears...
- MyFinishup();
-
- // Finally, quit app.
- ExitToShell();
- }
-
- //--------------------------------------------------------------------------
-
- // Clip Window support (MAS_showClip, MAS_drawClip, MAS_hideClip, and MAS_zoomClip):
-
- void MAS_showClip()
- {
- WindowPtr myWindow;
- Rect clipBounds;
-
- myWindow = (WindowPtr) WindowList;
- while (myWindow != nil) {
- if (IsMyClipWindow(myWindow)) {
- return;
- }
- myWindow = (WindowPtr) ((CWindowPeek) myWindow)->nextWindow;
- }
-
- SetRect(&clipBounds, 10, 400, 510, 480);
- myWindow = NewCWindow(0L, &clipBounds, "\PClipboard", TRUE, zoomDocProc, (WindowPtr) -1, TRUE, 0L);
- SetMyClipWindow(myWindow);
- SetPort(myWindow);
-
- gScrapCount = 0;
- gScrapType = 'NONE';
- if ((gScrap = NewHandle(0)) == nil) {
- MAS_ReportError("\PCould not create handle for scrap storage:", -1);
- ExitToShell();
- }
- }
-
- void MAS_drawClip(WindowPtr clipWindow)
- {
- PScrapStuff myScrapStuff;
- long scrapOffset, scrapLength;
- Rect myFrame;
- Str255 myStr;
- short moveSize;
-
- // See if scrap changed.
- myScrapStuff = InfoScrap();
- if (gScrapCount != myScrapStuff->scrapCount) {
- gScrapCount = myScrapStuff->scrapCount;
- if ((scrapLength = GetScrap(gScrap, 'PICT', &scrapOffset)) > 0) {
- gScrapType = 'PICT';
- } else if ((scrapLength = GetScrap(gScrap, 'TEXT', &scrapOffset)) > 0) {
- gScrapType = 'TEXT';
- } else
- gScrapType = 'NONE';
- }
-
- // Erase the window.
- EraseRect(&(clipWindow->portRect));
-
- // Draw something
- if (gScrapType == 'PICT') {
- myFrame = (**(PicHandle) gScrap).picFrame;
- SetWTitle(clipWindow, "\PClipboard contents: picture");
- DrawPicture((PicHandle) gScrap, &myFrame);
-
- } else if (gScrapType == 'TEXT') {
- SetWTitle(clipWindow, "\PClipboard contents: text");
- moveSize = GetHandleSize(gScrap);
- if (moveSize > 255)
- moveSize = 255;
- BlockMove(*gScrap, myStr+1, moveSize);
- myStr[0] = moveSize;
- MoveTo(10, 40);
- DrawString(myStr);
- } else
- SetWTitle(clipWindow, "\PNo PICT or TEXT to display.");
- }
-
- void MAS_hideClip(WindowPtr clipWindow)
- {
- DisposeWindow(clipWindow);
- gScrapCount = 0;
- gScrapType = 'NONE';
- DisposeHandle(gScrap);
- }
-
- void MAS_zoomClip(WindowPtr clipWindow, Boolean zoomOut)
- {
- WStateData *zoomData;
-
- // IMPORTANT: Must not change stdState if not zooming out. Otherwise, it will fool
- // the WDEF into thinking that it is not zoomed out when it really is.
-
- // Don't call anything else since zoomData handle is not locked.
- zoomData = (WStateData *) *(((CWindowPeek) clipWindow)->dataHandle);
-
- if (gScrapType == 'PICT') {
- if (zoomOut) {
- (zoomData->stdState).right = (zoomData->stdState).left +
- ((**(PicHandle) gScrap).picFrame).right;
- (zoomData->stdState).bottom = (zoomData->stdState).top +
- ((**(PicHandle) gScrap).picFrame).bottom;
- }
- } else if (gScrapType == 'TEXT') {
- if (zoomOut) {
- (zoomData->stdState).right = (zoomData->stdState).left + 620;
- }
- }
- }
-
- //--------------------------------------------------------------------------
-
- // Shell utilities (MAS_ReportError, and MAS_GetGlobalWindow):
-
- // Show Alert. Then, return true is err != noErr.
- Boolean MAS_ReportError(Str255 procStr, OSErr err)
- {
- long longerr = err;
- Str255 myStr;
-
- if (longerr) {
- NumToString(longerr, myStr);
- ParamText("\PFATAL ERROR", procStr, myStr, nil);
- Alert(ALERT_ERROR, nil);
- return(TRUE);
- } else
- return(FALSE);
- }
-
- void MAS_GetGlobalWindow(WindowPtr theWindow, Rect *windowRect)
- {
- // Get the windowRect in global coordinates.
- *windowRect = theWindow->portRect;
- LocalToGlobal(&topLeft(*windowRect));
- LocalToGlobal(&botRight(*windowRect));
- }
-
- //--------------------------------------------------------------------------
-
- // AppleEvents handling (AEOpenHandler, AEOpenDocHandler, AEPrintHandler,
- // and AECloseHandler) :
-
- pascal OSErr AEOpenHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
- // We don't do anything more than simply call MyNew().
- // Thus, when app is opened from finder, MyNew will be called because the Finder
- // will send an open app AppleEvent message.
- if (NEWDOCATSTARTUP)
- MyNew();
-
- return(noErr);
- }
-
- pascal OSErr AEOpenDocHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
- OSErr err;
- AEDescList docList;
- long numItems;
- FSSpec myFSS;
- Size actualSize;
- long i;
- DescType typeCode;
- AEKeyword theKeyword;
-
- if (err = AEGetParamDesc(messagein, keyDirectObject, typeAEList, &docList))
- return(err);
-
- if (err = AECountItems(&docList, &numItems))
- return(err);
-
- for (i=1; i<=numItems; i++) {
- if (err = AEGetNthPtr(&docList, i, typeFSS, &theKeyword, &typeCode, (Ptr) &myFSS,
- sizeof(FSSpec), &actualSize))
- return(err);
-
- MyOpen(&myFSS);
- }
-
- return(noErr);
- }
-
- pascal OSErr AEPrintHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
- OSErr err;
- AEDescList docList;
- long numItems;
- FSSpec myFSS;
- Size actualSize;
- long i;
- DescType typeCode;
- AEKeyword theKeyword;
-
- if (err = AEGetParamDesc(messagein, keyDirectObject, typeAEList, &docList))
- return(err);
-
- if (err = AECountItems(&docList, &numItems))
- return(err);
-
- for (i=1; i<=numItems; i++) {
- if (err = AEGetNthPtr(&docList, i, typeFSS, &theKeyword, &typeCode, (Ptr) &myFSS,
- sizeof(FSSpec), &actualSize))
- return(err);
-
- // Open each file. Print it. Then close it. MyOpen must make window frontmost.
- MyOpen(&myFSS);
- MyPrint();
- MyClose();
- }
-
- return(noErr);
- }
-
- pascal OSErr AEQuitHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
- gDoneFlag = TRUE;
-
- return(noErr);
- }
-